import { createStore } from 'vuex'

export const store = createStore({
  state: {
    count: 1
  },
  getters: {
    getCount: state => state.count
  },
  mutations: {
    changeCount(state, n: number) {
      if (n > 0) {
        state.count = n;
      }
    },
  },
  actions: {
    add({ commit }) {
      const count = this.state.count + 1;
      commit('changeCount', count)
    },
    del({ commit }) {
      const count = this.state.count - 1;
      commit('changeCount', count)
    }
  }
})